package com.imooc.web;

import com.imooc.web.exception.UserNotExistException;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@ControllerAdvice
public class ControllerExceptionHandler {

    @ResponseBody
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    @ExceptionHandler(value = UserNotExistException.class)
    public Map<String,Object> handlerUserNotExistException(UserNotExistException userNotExistException){
        ConcurrentHashMap<String, Object> map = new ConcurrentHashMap<>();
        map.put("id",userNotExistException.getId());
        map.put("error",userNotExistException.getMessage());
        return map;
    }
}
